<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />

			<cl-flex1 />
			<!-- 关键字搜索 -->
			<cl-search-key placeholder="搜索品牌名称、店铺名称、房间名称" />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" name="orderInfo-info" setup>
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";

const { service } = useCool();

// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			label: "时间范围",
			prop: "time",
			component: {
				name: "el-date-picker",
				props: {
					type: "datetimerange",
					valueFormat: "YYYY-MM-DD HH:mm:ss",
					defaultTime: ["2000-01-31T16:00:00.000Z", "2000-02-01T15:59:59.000Z"]
				}
			},
			required: true,
			hook: "datetimeRange"
		},
		{
			label: "时长",
			prop: "duration",
			hook: "number",
			component: { name: "el-input-number" },
			required: true
		},
		{
			label: "品牌id",
			prop: "brandId",
			hook: "number",
			component: { name: "el-input-number" },
			required: true
		},
		{
			label: "品牌名称",
			prop: "brandName",
			component: { name: "el-input", props: { clearable: true } },
			required: true
		},
		{
			label: "店铺id",
			prop: "shopId",
			hook: "number",
			component: { name: "el-input-number" },
			required: true
		},
		{
			label: "店铺名称",
			prop: "shopName",
			component: { name: "el-input", props: { clearable: true } },
			required: true
		},
		{
			label: "房间id",
			prop: "roomId",
			hook: "number",
			component: { name: "el-input-number" },
			required: true
		},
		{
			label: "房间名称",
			prop: "roomName",
			component: { name: "el-input", props: { clearable: true } },
			required: true
		}
	]
});

// cl-table
const Table = useTable({
	columns: [
		{ type: "selection" },
		{
			label: "开始时间",
			prop: "startTime",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" }
		},
		{
			label: "结束时间",
			prop: "endTime",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" }
		},
		{ label: "时长", prop: "duration", minWidth: 140 },
		{ label: "品牌id", prop: "brandId", minWidth: 140 },
		{ label: "品牌名称", prop: "brandName", minWidth: 140 },
		{ label: "店铺id", prop: "shopId", minWidth: 140 },
		{ label: "店铺名称", prop: "shopName", minWidth: 140 },
		{ label: "房间id", prop: "roomId", minWidth: 140 },
		{ label: "房间名称", prop: "roomName", minWidth: 140 },
		{
			label: "更新时间",
			prop: "updateTime",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" }
		},
		{
			label: "创建时间",
			prop: "createTime",
			minWidth: 170,
			sortable: "desc",
			component: { name: "cl-date-text" }
		},
		{ type: "op", buttons: ["edit", "delete"] }
	]
});

// cl-crud
const Crud = useCrud(
	{
		service: service.orderInfo.info
	},
	(app) => {
		app.refresh();
	}
);

// 刷新
function refresh(params?: any) {
	Crud.value?.refresh(params);
}
</script>
